package com.dolphin.fxc.auth.work.controller;

import com.dolphin.fxc.auth.work.pojo.entity.auth.AuthUserEntity;
import com.dolphin.fxc.auth.work.pojo.entity.auth.TokenEntity;
import com.dolphin.fxc.auth.work.service.SysUserService;
import com.dolphin.fxc.common.work.log.annotation.SysLog;
import com.dolphin.fxc.common.work.util.AssertUtil;
import com.dolphin.fxc.common.work.util.NoLogin;
import com.dolphin.fxc.common.work.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "web用户操作", description = "web用户接口")
@RestController
@RequestMapping("/sys-user")
@Slf4j
public class SysUserController {


    @Autowired
    private SysUserService sysUserService;

    /**
     * 用户登录
     *
     * @param authUserEntity 用户实体
     * @return 影响行数
     */
    @NoLogin
    @PostMapping("/login")
    @ApiOperation(notes = "用户登录", value = "用户登录")
    @SysLog("login")
    public R<TokenEntity> login(@RequestBody AuthUserEntity authUserEntity) {
        try {
            AssertUtil.hasLength(authUserEntity.getUserCode(), "用户名为空");
            AssertUtil.hasLength(authUserEntity.getPassword(), "密码为空");
            return R.ok(sysUserService.login(authUserEntity));
        } catch (Exception ex) {
            return R.failed(ex.getMessage(), "1234567");
        }
    }


    /**
     * 测试鉴权
     */
    @PostMapping("/testAuth")
    @ApiOperation(notes = "测试鉴权", value = "测试鉴权")
    @SysLog("testAuth")
    public void testAuth() {
        log.info("11111");
    }
//        /**
//         * 用户退出登录
//         *
//         * @param request请求
//         * @return 影响行数
//         */
//        @NoLogin
//        @PostMapping("/logout")
//        public void logout(HttpServletRequest request) {
//            userService.logout(request);
//        }  @ApiOperation(notes = "用户退出登录", value = "用户退出登录")
//

}
